package builder

import (
	"fmt"
	"time"
)

// Customer 客户信息
type Customer struct {
	Name    string
	Email   string
	Address string
}

// Item 订单项
type Item struct {
	ProductID string
	Name      string
	Quantity  int
	Price     float64
}

// Payment 支付信息
type Payment struct {
	Method string
	Amount float64
}

// Shipping 配送信息
type Shipping struct {
	Method    string
	Cost      float64
	TrackCode string
}

// Order 订单实体
type Order struct {
	ID        string
	CreatedAt time.Time
	Customer  Customer
	Items     []Item
	Payment   Payment
	Shipping  Shipping
}

// TotalAmount 计算订单总金额
func (o *Order) TotalAmount() float64 {
	total := 0.0
	for _, item := range o.Items {
		total += item.Price * float64(item.Quantity)
	}
	return total
}

// 订单信息字符串表示
func (o *Order) String() string {
	str := fmt.Sprintf("订单号: %s\n创建时间: %s\n", o.ID, o.CreatedAt.Format("2006-01-02 15:04:05"))
	str += fmt.Sprintf("客户: %s <%s>\n地址: %s\n", o.Customer.Name, o.Customer.Email, o.Customer.Address)
	str += "商品列表:\n"
	for i, item := range o.Items {
		str += fmt.Sprintf("  %d. [%s] %s - ¥%.2f x %d\n", i+1, item.ProductID, item.Name, item.Price, item.Quantity)
	}
	str += fmt.Sprintf("支付方式: %s, 金额: ¥%.2f\n", o.Payment.Method, o.Payment.Amount)
	str += fmt.Sprintf("配送方式: %s, 运费: ¥%.2f\n", o.Shipping.Method, o.Shipping.Cost)
	str += fmt.Sprintf("订单总额: ¥%.2f", o.TotalAmount())
	return str
}
